package com.gwl.concurrent.simple;

import java.util.concurrent.TimeUnit;
import static java.lang.System.out; 

class Sleeper extends Thread {
	@Override
	public void run() {
		try {
			TimeUnit.MILLISECONDS.sleep(1000); 
		} catch (InterruptedException e) {
			out.println("Sleeper interrupted"); 
		} 
		out.println("Sleeper awakened"); 
	} 
}
class Joiner extends Thread { 
	private Thread sleeper; 
	public Joiner(Thread sleeper) { 
		this.sleeper = sleeper; 
	}
	@Override
	public void run() {
		try { 
			TimeUnit.MILLISECONDS.sleep(100);
			sleeper.join(); 
		} catch (InterruptedException e) {
			out.println("Sleeper interrupted"); 
		} 
		out.println("Joiner completed"); 
	} 
}

public class Joining {
	public static void main(String[] args) {
		Thread sleeper = new Sleeper(); 
		Thread joiner = new Joiner(sleeper); 
		sleeper.start(); 
		joiner.start(); 
	} 
}
